package com.redsoil.house.ui.login.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.redsoil.house.R;
import com.redsoil.house.base.BaseActivity;
import com.redsoil.house.ui.login.contract.ForgotPwdContract;
import com.redsoil.house.ui.login.presenter.FotgotPwdPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 找回密码页面
 */
public class ForgotPwdActivity extends BaseActivity<FotgotPwdPresenter> implements ForgotPwdContract.View{

    @BindView(R.id.close_img)
    ImageView close_img;

    @BindView(R.id.email_edit)
    EditText email_edit;

    @BindView(R.id.sure_button)
    Button sure_button;

    @Override
    protected int getLayout() {
        return R.layout.activity_forgot_pwd;
    }

    @Override
    protected void initEventAndData() {

    }

    @OnClick(R.id.close_img)
    void onClose(){
        finish();
    }

    @OnClick(R.id.sure_button)
    void onSureButton(){
        sure_button.setEnabled(false);
        String email = email_edit.getText().toString();

        //1.判断账号不能为空
        if (StringUtils.isSpace(email)) {
            ToastUtils.showShortToast("邮箱不能为空");
            sure_button.setEnabled(true);
        } else {
            mPresenter.findPwd(email);
        }
    }

    @Override
    public void findPwdSuccess() {
        sure_button.setEnabled(true);
        ToastUtils.showShortToast("密码已发送到邮箱");
    }

    @Override
    public void responeError(String errorMsg) {
        sure_button.setEnabled(true);
        ToastUtils.showShortToast("密码找回失败，请检查邮箱是否正确");
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    /**
     * 打开新Activity
     *
     * @param context
     * @return
     */
    public static Intent newInstance(Context context) {
        Intent intent = new Intent(context, ForgotPwdActivity.class);
        return intent;
    }

}
